package net.arvin.utils;

import org.apache.http.HttpEntity;

import android.content.Context;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;

/**
 * Asynchronous HTTP client's utility.
 * 
 */
public final class AsyncHttpClientUtil {

	private AsyncHttpClientUtil() {
	}

	/**
	 * Start a get request.
	 * 
	 * @param client
	 * @param url
	 * @param handler
	 */
	public static void get(final AsyncHttpClient client, final String url,
			final Context context, final AsyncHttpResponseHandler handler) {
		client.get(context, url, handler);
	}

	public static void post(final AsyncHttpClient client, final String url,
			final AsyncHttpResponseHandler handler) {
		client.post(url, handler);
	}

	/**
	 * Start a get request with parameters.
	 * 
	 * @param client
	 * @param url
	 * @param params
	 * @param handler
	 */
	public static void get(final AsyncHttpClient client, final String url,
			final RequestParams params, final AsyncHttpResponseHandler handler) {
		client.get(url, params, handler);
	}

	public static void post(final AsyncHttpClient client, final String url,
			final RequestParams params, final AsyncHttpResponseHandler handler) {
		client.post(url, params, handler);
	}

	public static void get(final AsyncHttpClient client, final String url,
			final Context context, final RequestParams params,
			final AsyncHttpResponseHandler handler) {
		client.get(context, url, params, handler);
	}

	/**
	 * Start a post request.
	 * 
	 * @param client
	 * @param url
	 * @param context
	 * @param entity
	 * @param handler
	 */
	public static void post(final AsyncHttpClient client, final String url,
			final Context context, final HttpEntity entity,
			final AsyncHttpResponseHandler handler) {
		client.post(context, url, entity, "application/x-www-form-urlencoded",
				handler);
	}

	/**
	 * Start a delete request.
	 * 
	 * @param client
	 * @param url
	 * @param context
	 * @param requestParams
	 * @param handler
	 */
	public static void delete(final AsyncHttpClient client, final String url,
			final Context context, final RequestParams params,
			final AsyncHttpResponseHandler handler) {
		client.delete(context, url, null, params, handler);
	}
}